<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class CUserValid extends CUserComponent
{
    public $validType;
    
    public function  __construct()
    {
    }


    
    public function validUser($userName, $password){
                        if ($userName == "admin"){
            $iuser = new COwnerUser();
        } else {
            $iuser = $this->getObject();
        }
        if ($iuser == false){
            return false;
        }

        $userInfo = array();
        $userInfo['userName'] = $userName;
        $userInfo['password'] = $password;

        $userData = $iuser->getUser($userInfo);
        if (!$userData){
                        if ($iuser->judgeSelf()){
                $user = $this->validUserSelf($userName, $password);
                return $user;
            }
            return false;
        }
        $user = $this->storeUser($userData);
        return $user;

    }

    
    public function validUserSelf($userName, $password){
        $user =  User::model()->find("user_name=?", array($userName));
        if (empty($user)){
            return false;
        }

        if ($user['user_status'] == 0){
            return false;
        }

        $signPassword = CSecret::passSign($password, $user["salt"]);
        if ($user["user_pass"] == $signPassword){
            return $user;
        }
        return false;
    }
}
?>